package com.study.demo.aop.demo1;

import com.study.demo.aop.demo.XiaoMing;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Cache
 * xml配置方式
 * 直接通过一个相对简单一点的使用实例(Cacheable), 来看一下 aop 是怎么使用的
 * @author: elvin
 * @time: 2019-05-21 09:49
 * @desc:
 **/
public class Start1 {
    public static void main(String[] args){
        ApplicationContext ct  = new ClassPathXmlApplicationContext("classpath:demo1/aop.xml");
       IUserService service = (IUserService)ct.getBean("userService");
        System.out.println("==========第一次获取====================");
        User user = service.getDefault();
        System.out.println("方法调用结束, 获取到的结果为: " + user.toString());

        System.out.println("==========第二次获取====================");
        User user1 = service.getDefault();
        System.out.println("方法调用结束, 获取到的结果为: " + user1.toString());


        //cacheAblePutEvict(service);
    }

    /**
     * 验证 Cacheable 和 CachePut 的作用
     * @param service
     */
    private static void cacheAblePutEvict(UserService service) {
        System.out.println("==========getById 1 第一次获取====================");
        User user = service.getById(1);
        System.out.println(user.toString());

        System.out.println();
        System.out.println("========== getById 1 第二次获取====================");
        user = service.getById(1);
        System.out.println(user.toString());

        System.out.println();
        System.out.println("========== getById 2 第一次获取====================");
        user = service.getById(2);
        System.out.println(user.toString());

        System.out.println();
        System.out.println("==========getByIdPut 3 第一次获取====================");
        user = service.getByIdPut(3);
        System.out.println(user.toString());

        System.out.println();
        System.out.println("==========getById 3 第一次获取====================");
        user = service.getById(3);
        System.out.println(user.toString());

        System.out.println();
        System.out.println("==========getByIdPut 3 第二次获取====================");
        user = service.getByIdPut(3);
        System.out.println(user.toString());

        System.out.println();
        System.out.println("==========getById 3 第二次获取====================");
        user = service.getById(3);
        System.out.println(user.toString());

        System.out.println();
        System.out.println("==========clearBy 3 第一次清除====================");
        service.clearBy(3);

        System.out.println();
        System.out.println("==========getById 3 第三次获取====================");
        user = service.getById(3);
        System.out.println(user.toString());
    }
}
